package validator

import (
	"context"
	"github.com/go-playground/locales"
	"github.com/go-playground/locales/en"
	"github.com/go-playground/locales/zh"
	ut "github.com/go-playground/universal-translator"
	"github.com/go-playground/validator/v10"
)

var defaultValidator *Validate

func init() {
	supports := []locales.Translator{en.New(), zh.New()}
	defaultValidator = &Validate{engine: validator.New(), translator: ut.New(supports[0], supports[1:]...)}

	for _, s := range supports {
		/* 注册翻译 */
		_ = defaultValidator.initTranslations(s.Locale())
	}
	/* 注册校验 */
	_ = defaultValidator.initValidations()
}

func StructCtx(ctx context.Context, s any) error {
	return defaultValidator.StructCtx(ctx, s)
}
